package app.pub.json;

import java.util.ArrayList;
import java.util.Map;

import net.sf.json.JSONArray;

public class JsonUtil {

    public static ArrayList<Map<String, Object>> formatJson2Map(String json) {
        ArrayList<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
        try {
            JSONArray jsonArray = JSONArray.fromObject(json);
            if (jsonArray.size() > 0) {
                for (int i = 0; i < jsonArray.size(); i++) {
                    Object objRow = jsonArray.get(i);
                    Map<String, Object> rowMap = (Map<String, Object>) objRow;  
                    for (String columnName : rowMap.keySet()) {
                        if (rowMap.get(columnName) != null) {
                            String c_name = columnName.trim();
                            Object c_value = rowMap.get(columnName);
                            rowMap.put(c_name, c_value);
                        }
                    }
                    returnList.add(rowMap);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return returnList;
    }

    public static void main(String[] args) {

    }

}
